﻿using System.Drawing;
using System.IO;

namespace Database
{
    internal class ImageHelper
    {
        public static byte[] ImageToByteArray(Image imageToConvert,
                                              System.Drawing.Imaging.ImageFormat formatOfImage)
        {
            byte[] result;
            using (var ms = new MemoryStream())
            {
                imageToConvert.Save(ms, formatOfImage);
                result = ms.ToArray();
            }
            return result;
        }

        public static Image ByteArrayToImage(byte[] data)
        {
            var ms = new MemoryStream(data);
            return Image.FromStream(ms);
        }
    }
}
